package org.jsbd.boss.domian;

import org.jsbd.boss.annotation.ExportExcelAnnotation;
import org.jsbd.boss.common.DataGridModel;

import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Random;

public class Book {

	private Integer id;

	private Integer bookGroupId;

	private String mark;

	@ExportExcelAnnotation(index = 0)
	private String name;

	@ExportExcelAnnotation(index = 1)
	private Integer chapter; // 书章节

	@ExportExcelAnnotation(index = 2)
	private BigDecimal totalMoney; // 总金额

	@ExportExcelAnnotation(index = 3)
	private BigDecimal payMoney; //已支付金额

	private transient Integer flag = 0;
	
	@ExportExcelAnnotation(index = 4)
	private Integer failCount = 0;

	private Date createTime;
	private Date modifyTime;

	private transient DataGridModel pageInfo;

	public void updateChapter() {
		int c = chapter.intValue();
		if (c < 0) {
			chapter = 0;
			return;
		}
		if (c == 0) {
			return;
		}

		int i = 0;
		Random random = new Random();
		if (c == 1) {
			i = random.nextInt(3);
			chapter += i;
			return;
		} else if (c == 2) {
			i = random.nextInt(4);
			if (i == 1 || i == 2) {
				chapter += i;
			} else if (i == 3) {
				chapter -= 1;
			}
			return;
		} else {
			i = random.nextInt(5);
			if (i == 1 || i == 2) {
				chapter -= i;
			} else if (i == 3 || i == 4) {
				chapter += (i - 2);
			}
		}
	}

	public String getMark() {
		return mark;
	}

	public void setMark(String mark) {
		this.mark = mark;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getBookGroupId() {
		return bookGroupId;
	}

	public void setBookGroupId(Integer bookGroupId) {
		this.bookGroupId = bookGroupId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getChapter() {
		return chapter;
	}

	public void setChapter(Integer chapter) {
		this.chapter = chapter;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}

	public Integer getFlag() {
		return flag;
	}

	public void setFlag(Integer flag) {
		this.flag = flag;
	}

	public DataGridModel getPageInfo() {
		return pageInfo;
	}

	public void setPageInfo(DataGridModel pageInfo) {
		this.pageInfo = pageInfo;
	}

	public BigDecimal getTotalMoney() {
		return totalMoney;
	}

	public void setTotalMoney(BigDecimal totalMoney) {
		this.totalMoney = totalMoney;
	}

	public BigDecimal getPayMoney() {
		return payMoney;
	}

	public void setPayMoney(BigDecimal payMoney) {
		this.payMoney = payMoney;
	}
	
	public Integer getFailCount() {
		return failCount;
	}

	public void setFailCount(Integer failCount) {
		this.failCount = failCount;
	}

	@Override
	public String toString() {
		return JSONObject.toJSONString(this);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (obj instanceof Book) {
			Book other = (Book) obj;
			if (this.name.equals(other.getName()))
				return true;
		}
		return false;
	}

}